home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 4 / Precision Software Applications Silver Collection Volume 4 (1993).iso / stats / chadyn.exe / YXCROSS.C < prev    next >
C/C++ Source or Header  |  1988-12-08  |  5KB  |  157 lines

  1. /* YXCROSS.C - X windows routines for handling crosses.
  2.  * Written by Eric Kostelich, Institute for Physical Science and Technology,
  3.  * University of Maryland, College Park, MD  20742.
  4.  * Copyright (c) 1988 by James A. Yorke.
  5.  */
  6. #define XINCLUDES
  7. #include "yinclud.h"
  8. #ifdef X11
  9.  
  10. typedef struct {
  11.     int    width, height;        /* total size in pixels of cross */
  12.     Pixmap    contents;        /* of region before cross was drawn */
  13.     POINT    origin;            /* of upper left hand corner of 
  14.                      * saved contents rectangle */
  15. } CROSSINFO;
  16.  
  17. extern POINT    *FindPixel();
  18. static CROSSINFO scrncross[2];
  19.  
  20. /* ------------------------------------------------------------------- */
  21. /* CROSS - Place a cross at (x, y) containing W pixels on either side of
  22.  * X and H pixels on either side of Y.  If PICNUM is equal to
  23.  * SCRN, then the cross is placed on the screen; otherwise the cross is
  24.  * drawn on the core copy.  Crosses come in only two flavors:  BIGCROSS and
  25.  * SMALLCROSS.
  26.  * Note:  This routine is not reentrant; it erases any previous cross
  27.  * of the same flavor before displaying the current cross.
  28.  * Note 2:  For the moment, this routine does nothing unless PICNUM is the
  29.  * screen, and FLAVOR is one of BIGCROSS or SMALLCROSS.
  30.  */
  31. cross(xval, yval, w, h, picnum, flavor)
  32. double    xval, yval;    /* center of new cross to be drawn */
  33. int    w;        /* have W pixels on either side of center unless we
  34.              * hit the sides of the window */
  35. int    h;        /* have H pixels on top and bottom unless we hit
  36.              * the side of the window */
  37. int    picnum;        /* SCRN for screen; otherwise core copy */
  38. int    flavor;        /* BIGCROSS or SMALLCROSS */
  39. {
  40.     CROSSINFO    *c;
  41.     POINT    *p;
  42.     XSegment    cseg[2];
  43.     int    cwidth, cheight;    /* of cross to be placed */
  44.     int    xoff, yoff;        /* of upper left corner of imaginary
  45.                      * box circumscribing the cross */
  46.  
  47.     if((p = FindPixel(xval, yval, picnum)) == NULL 
  48.        || flavor != BIGCROSS && flavor != SMALLCROSS)
  49.         return;
  50.     if(picnum == SCRN)  {
  51.         c = &scrncross[flavor];
  52.  
  53.         /* Restore previous contents behind existing cross and
  54.          * reclaim storage if sizes of crosses have changed
  55.          */
  56.         if(c->contents != (Pixmap) 0)
  57.             XCopyArea(x_dpy, c->contents, x_window, x_gc,
  58.                0, 0, c->width, c->height, c->origin.x, c->origin.y);
  59.         xoff = max(p->x - w, 0);
  60.         yoff = max(p->y - h, 0);
  61.         cwidth = min(scrncols, p->x + w) - xoff + 1;
  62.         cheight = min(scrnrows, p->y + h) - yoff + 1;
  63.         if(c->contents != (Pixmap) 0 && 
  64.            (cwidth != c->width || cheight != c->height))  {
  65.             XFreePixmap(x_dpy, c->contents);
  66.             c->contents = (Pixmap) 0;
  67.         }
  68.         if(c->contents == (Pixmap) 0)  {
  69.             c->contents = XCreatePixmap(x_dpy, x_window, cwidth,
  70.                     cheight, 1);
  71.             c->width = cwidth;
  72.             c->height = cheight;
  73.         }
  74.         c->origin.x = xoff;
  75.         c->origin.y = yoff;
  76.  
  77.         /* Save contents of screen in the box which will contain 
  78.          * the cross and draw the cross on the screen.
  79.          */
  80.         XCopyArea(x_dpy, x_window, c->contents, x_gc, xoff, yoff,
  81.             cwidth, cheight, 0, 0);
  82.         cseg[0].x1 = xoff;
  83.         cseg[0].x2 = xoff + cwidth - 1;
  84.         cseg[0].y1 = p->y;
  85.         cseg[0].y2 = p->y;
  86.         cseg[1].x1 = p->x;
  87.         cseg[1].x2 = p->x;
  88.         cseg[1].y1 = yoff;
  89.         cseg[1].y2 = yoff + cheight - 1;
  90.         XDrawSegments(x_dpy, x_window, x_gc, &cseg[0], 2);
  91.     }
  92.     return;
  93. }
  94. /* ------------------------------------------------------------------- */
  95. /* CRTCROSSON - Place a permanent cross on the screen at (x, y) 
  96.  * containing W pixels on either side of X and H pixels on either side of Y.  
  97.  * Note: for the moment, COLOR is a dummy argument.
  98.  */
  99.  
  100. CRTcrossON(xval, yval, m, n, hue)
  101. double    xval, yval;    /* center of new cross to be drawn */
  102. int    m;        /* have M pixels on either side of center unless we
  103.              * hit the sides of the window */
  104. int    n;        /* have N pixels on top and bottom unless we hit
  105.              * the side of the window */
  106. unsigned hue;        /* dummy for now */
  107. {
  108.     POINT    *p;
  109.     XSegment    cseg[2];
  110.     int    xoff, yoff;        /* of upper left corner of imaginary
  111.                      * box circumscribing the cross */
  112.  
  113.     if((p = FindPixel(xval, yval, SCRN)) == NULL)
  114.         return;
  115.     xoff = max(p->x - m, 0);
  116.     yoff = max(p->y - n, 0);
  117.  
  118.     /* Place the cross as a pair of segments */
  119.  
  120.     cseg[0].x1 = xoff;
  121.     cseg[0].x2 = min(scrncols, p->x + m) + 1;
  122.     cseg[0].y1 = p->y;
  123.     cseg[0].y2 = p->y;
  124.     cseg[1].x1 = p->x;
  125.     cseg[1].x2 = p->x;
  126.     cseg[1].y1 = yoff;
  127.     cseg[1].y2 = min(scrnrows, p->y + n) + 1;
  128.     XDrawSegments(x_dpy, x_window, x_gc, &cseg[0], 2);
  129.     return;
  130. }
  131. /* ------------------------------------------------------------------- */
  132. /* TURNOFF - turn off the appropriate cross by restoring the obscured
  133.  * area of the screen, if any.  Return the storage used to retain the
  134.  * obscured area.
  135.  */
  136. turnoff(crossnumber)
  137. int    crossnumber;
  138. {
  139.     register CROSSINFO    *c;
  140.  
  141.     if(crossnumber == BIGCROSS || crossnumber == SMALLCROSS)  {
  142.         c = &scrncross[crossnumber];
  143.         if(c->contents != (Pixmap) 0)  {
  144.             XCopyArea(x_dpy, c->contents, x_window, x_gc,
  145.                0, 0, c->width, c->height, c->origin.x, c->origin.y);
  146.             XFreePixmap(x_dpy, c->contents);
  147.             c->contents = (Pixmap) 0;
  148.         }
  149.         if(crossnumber == BIGCROSS)
  150.             IsCross0Set = NO;
  151.         else
  152.             IsCross1Set = NO;
  153.     }
  154.     return;
  155. }
  156. #endif    /* X11 */
  157.